package com.meiya.baseweb.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.meiya.baseweb.common.PropertyFilter;
import com.meiya.baseweb.dao.IFactDao;
import com.meiya.baseweb.dao.IOpinionDao;
import com.meiya.baseweb.dao.IPubopinionDao;
import com.meiya.baseweb.entity.Fact;
import com.meiya.baseweb.entity.Opinion;
import com.meiya.baseweb.entity.Pubopinion;
import com.meiya.baseweb.service.IPublicOpinionViewService;

@Service
public class PublicOpinionViewDaoResource implements IPublicOpinionViewService {

	@Resource
	private IPubopinionDao pubopinionDao;
	@Resource
	private IFactDao factDao;
	@Resource
	private IOpinionDao opinionDao;

	public void addNewPublicOpinion(Pubopinion p) {
		// 1. add pubopinion
		pubopinionDao.newEntity(p);
		
		// 2. add fact
		Fact f=new Fact();
		f.setTitle(p.getTitle()+"事件");
		f.setThePubopinion(p);
		factDao.newEntity(f);
		
		// 3. add opinions
		Opinion op1=new Opinion();
		Opinion op2=new Opinion();

		op1.setTitle(p.getTitle()+"正面");
		op2.setTitle(p.getTitle()+"反面");
		op1.setThePubopinion(p);
		op2.setThePubopinion(p);

		opinionDao.newEntity(op1);
		opinionDao.newEntity(op2);
		
	}

	public Pubopinion getSinglePubopinion(String filter) {
		return pubopinionDao.getEntityByProperties(PropertyFilter.parsePropertyFilterExp(filter));
	}

	public void removePubopinion(Pubopinion p) {
		pubopinionDao.deleteEntity(p);
	}

	public void addPubopinion(Pubopinion p) {
		pubopinionDao.newEntity(p);
	}

	public void addOpinion(Opinion o) {
		opinionDao.newEntity(o);
	}

	public void addFact(Fact f) {
		factDao.newEntity(f);
	}
}
